<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Column as Col;
use addons\BuilderPlus\components\Edit;
use addons\BuilderPlus\components\Search;
use addons\BuilderPlus\facade\Table;

class News extends Base
{
    public function getOptions(): array
    {
        return [
            'pk'    => 'id',
            'model' => \app\common\model\News::class
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->addColumns([
                ['id', 'ID', fn(Col $col) => $col->width(80)],
                ['images', '缩略图', fn(Col $col) => $col->width(80)->lazyImage(), fn(Edit $e) => $e->images()],
                ['title', '标题', null, fn(Edit $e) => $e->require()],
                ['content', '详情',  fn(Col $col) => $col->hide(), fn(Edit $e) => $e->editor()],
                ['sort', '排序', fn(Col $col) => $col->fastSort(), fn(Edit $e) => $e->number()],
                ['create_time', '添加时间', fn(Col $col) => $col->width(140)],
                ['status', '状态', fn(Col $col) => $col->switch('开启|关闭', '1|0')->fixed('right')]
            ])
            ->addTopButtons(['add', 'deleteAll'])
            ->addRightButtons(['edit', 'delete'])
            ->addSearch([
                ['title', '标题筛选', fn(Search $search) => $search->condition('Like')],
                ['create_time', '添加时间', fn(Search $search) => $search->type('date')]
            ])
            ->fetch();
    }

}
